package dayPractice.递归回溯;

import java.util.*;

class Main{
    
    static int n;
    static boolean[] vis;
    static int[] st;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        vis = new boolean[n];
        st = new int[n];
        dfs(0);
    }
    
    static void dfs(int u){
        if(u == n){
            for(int i = 0; i < n; i ++){
                System.out.print(st[i] + " ");
            }
            System.out.println();
            return ;
        }
        for(int i = 0; i < n; i ++){
            if(!vis[i]){
                vis[i] = true;
                st[u] = i + 1;
                dfs(u + 1);
                st[u] = 0;
                vis[i] = false;
            }
        }
    }
}